/**
 * Moodle forms HTML isn't changeable via renderers (yet?) so this
 * .less file imports styles from the bootstrap @variables file and
 * adds them to the existing Moodle form CSS ids and classes.
 *
 */

form {
    margin: 0;
}
.mform fieldset .advancedbutton {
    text-align: right;
}
.jsenabled .mform .containsadvancedelements .advanced {
    display: none;
}
.mform .containsadvancedelements .advanced.show {
    display: block;
}
.mform fieldset.group {
    margin-bottom: 0
}
.mform fieldset.error {
    border: 1px solid @errorText;
}
.mform span.error,
#adminsettings span.error {
    display: inline-block;
    border: 1px solid @errorBorder;
    border-radius: 4px;
    background-color: @errorBackground;
    padding: 4px;
    margin-bottom: 4px;
}
.mform fieldset.collapsible legend a.fheader {
    padding: 0 5px 0 20px;
    margin-left: -20px;
    background: url([[pix:t/expanded]]) 2px center no-repeat;
}
.dir-rtl .mform fieldset.collapsible legend a.fheader {
    padding: 0 20px 0 5px;
    margin-right: -20px;
    margin-left: 0;
    background-position: right center;
}
.mform fieldset.collapsed legend a.fheader {
    background-image: url([[pix:t/collapsed]]);
}
.dir-rtl .mform fieldset.collapsed legend a.fheader {
    background-image: url([[pix:t/collapsed_rtl]]);
}
.jsenabled .mform .collapsed .fcontainer {
    display: none;
}

.mform .fitem .fitemtitle div {
    display: inline;
}
#adminsettings .error,
.loginpanel .error,
.mform .error {
    color: @errorText;
}
.mform .fdescription.required {
    margin-left: @horizontalComponentOffset;
}
.mform .fpassword .unmask {
    display: inline-block;
    margin-left: 0.5em;
    & > input {
        margin: 0;
    }
    & > label {
        display: inline-block;
    }
}
.mform label {
    display: inline-block;
}

.mform .iconhelp {
    margin-left: 4px;
}
.dir-rtl .mform .iconhelp {
    margin-right: 4px;
}
.mform .ftextarea #id_alltext {
    width: 100%;
}
.mform ul.file-list {
    padding: 0;
    margin: 0;
    list-style: none;
}
.mform label .req,
.mform label .adv {
    cursor: help;
}
.mform .fcheckbox input {
    margin-left: 0;
}
.mform .fcheckbox > span,
.mform .fradio > span,
.mform .fgroup > span {
    display: inline-block;
    margin-top: 5px;
}
.mform .fitem fieldset.fgroup label,
.mform fieldset.fdate_selector label {
    display: inline;
    float: none;
    width: auto;
}
.mform .ftags label.accesshide {
    display: block;
    position: static;
}
.mform .ftags select {
    margin-bottom: 0.7em;
    min-width: 22em;
}
.mform .helplink img {
    margin: 0 .45em;
    padding: 0;
}
.mform legend .helplink img {
    margin: 0 .2em;
}
.singleselect label {
    margin-right: .3em;
}
.dir-rtl .singleselect label {
    margin-left: .3em;
    margin-right: 0;
}
input#id_externalurl {
    direction: ltr;
}
#portfolio-add-button {
    display: inline;
}

// Copying in Bootstrap styles.
.form-item,
.mform .fitem {
    .form-horizontal .control-group;
    margin-bottom: 10px;
    // Theres's a mysterious extra 10px inside this item,
    // so reduce margin by 10px from 20px standard to compensate.
}
.form-item .form-label,
.mform .fitem div.fitemtitle {
    .form-horizontal .control-label
}
.dir-rtl {
    .form-item .form-label,
    .mform .fitem div.fitemtitle {
        float:right;
        text-align: left;
    }
}
.form-defaultinfo,
.form-label .form-shortname {
    .muted;
}
.form-label .form-shortname {
    font-size: @fontSizeMini;
    display: block;
}
.dir-rtl .form-label .form-shortname {
    text-align: left;
}
.form-item .form-setting,
.form-item .form-description,
.mform .fitem .felement,
#page-mod-forum-search .c1 {
    .form-horizontal .controls
}


.formsettingheading {
    .form-horizontal .help-block
}
// Moodle doesn't differentiate between what Bootstrap calls
// .uneditable-inputs and form help text. Styling them both as
// uneditable looks ugly, styling both as form help is fairly
// subtle in it's impact. Going for the latter as the best option.
.form-item .form-description,
.felement.fstatic {
    .help-block;
    padding-top: 5px;
}
.form-item .form-description {
    padding-top: 0;
}
.fitem .fstaticlabel {
    font-weight: bold;
}

// Pale grey container for submit buttons.
table#form td.submit,
.form-buttons,
.path-admin .buttons,
#fitem_id_submitbutton,
.fp-content-center form + div,
div.backup-section + form,
#fgroup_id_buttonar {
    .form-actions;
    padding-left: 0;
}
.path-admin .buttons,
.form-buttons { // Add back the padding it would usually get from being inside a .form-horizontal.
    padding-left: @horizontalComponentOffset;
}
.dir-rtl {
    table#form td.submit,
    .form-buttons,
    .path-admin .buttons,
    #fitem_id_submitbutton,
    .fp-content-center form + div,
    div.backup-section + form,
    #fgroup_id_buttonar {
        .form-actions;
        padding-right: 0;
    }
    .path-admin .buttons,
    .form-buttons { // Add back the padding it would usually get from being inside a .form-horizontal.
        padding-right: @horizontalComponentOffset;
    }
}
.form-item .form-setting .form-checkbox.defaultsnext {
    // Need to specify .defaultsnext and the .form-checkbox class
    // is somewhat randomly re-used on various actual checkboxes
    // throughout the admin forms, instead of on the wrapper div.
    margin-top: 5px; // Push down checkboxes to align.
    display: inline-block; // So above style sticks.
}

#adminsettings h3 {
    // Copied from bootstrap/forms.less tag legend.
    display: block;
    width: 100%;
    padding: 0;
    margin-bottom: @baseLineHeight;
    font-size: @baseFontSize * 1.5;
    line-height: @baseLineHeight * 2;
    color: @grayDark;
    border: 0;
    border-bottom: 1px solid #e5e5e5;
}
.mform legend a,
.mform legend a:hover {
    color: @textColor;
    text-decoration: none;
}
.dir-rtl .mform .fitem .felement {
    margin-right: 30%;
    margin-left: auto;
    text-align: right;
}
// I think this could be avoided (or at least tidied up) ifr
// we used HTML5 input types like url, phone, email, number etc.
.dir-rtl .mform .fitem .felement input[name=email],
.dir-rtl .mform .fitem .felement input[name=email2],
.dir-rtl .mform .fitem .felement input[name=url],
.dir-rtl .mform .fitem .felement input[name=idnumber],
.dir-rtl .mform .fitem .felement input[name=phone1],
.dir-rtl .mform .fitem .felement input[name=phone2] {
    text-align: left;
    direction: ltr;
}
.dir-rtl #id_s__pathtodu,
.dir-rtl #id_s__aspellpath,
.dir-rtl #id_s__pathtodot,
.dir-rtl #id_s__supportemail,
.dir-rtl #id_s__supportpage,
.dir-rtl #id_s__sessioncookie,
.dir-rtl #id_s__sessioncookiepath,
.dir-rtl #id_s__sessioncookiedomain,
.dir-rtl #id_s__proxyhost,
.dir-rtl #id_s__proxyuser,
.dir-rtl #id_s__proxypassword,
.dir-rtl #id_s__proxybypass,
.dir-rtl #id_s__jabberhost,
.dir-rtl #id_s__jabberserver,
.dir-rtl #id_s__jabberusername,
.dir-rtl #id_s__jabberpassword,
.dir-rtl #id_s__additionalhtmlhead,
.dir-rtl #id_s__additionalhtmltopofbody,
.dir-rtl #id_s__additionalhtmlfooter,
.dir-rtl #id_s__docroot,
.dir-rtl #id_s__filter_tex_latexpreamble,
.dir-rtl #id_s__filter_tex_latexbackground,
.dir-rtl #id_s__filter_tex_pathlatex,
.dir-rtl #id_s__filter_tex_pathdvips,
.dir-rtl #id_s__filter_tex_pathconvert,
.dir-rtl #id_s__blockedip,
.dir-rtl #id_s__pathtoclam,
.dir-rtl #id_s__quarantinedir,
.dir-rtl #id_s__sitepolicy,
.dir-rtl #id_s__sitepolicyguest,
.dir-rtl #id_s__cronremotepassword,
.dir-rtl #id_s__allowedip,
.dir-rtl #id_s__blockedip,
.dir-rtl #id_s_enrol_meta_nosyncroleids,
.dir-rtl #id_s_enrol_ldap_host_url,
.dir-rtl #id_s_enrol_ldap_ldapencoding,
.dir-rtl #id_s_enrol_ldap_bind_dn,
.dir-rtl #id_s_enrol_ldap_bind_pw,
.dir-rtl #admin-emoticons .form-text,
.dir-rtl #admin-role_mapping input[type=text],
.dir-rtl #id_s_enrol_paypal_paypalbusiness,
.dir-rtl #id_s_enrol_flatfile_location,
#page-admin-setting-enrolsettingsflatfile.dir-rtl input[type=text],
#page-admin-setting-enrolsettingsdatabase.dir-rtl input[type=text],
#page-admin-auth-db.dir-rtl input[type=text] {
    direction: ltr;
}
#page-admin-setting-enrolsettingsflatfile.dir-rtl .informationbox {
    direction: ltr;
    text-align: left;
}
#page-admin-grade-edit-scale-edit.dir-rtl .error input#id_name {
    margin-right: 170px;
}
#page-grade-edit-outcome-course .courseoutcomes {
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}
#page-grade-edit-outcome-course .courseoutcomes td {
    text-align:center;
}
/* Install Process' text fields Forms, should always be justified to the left */
#installform #id_wwwroot,
#installform #id_dirroot,
#installform #id_dataroot,
#installform #id_dbhost,
#installform #id_dbname,
#installform #id_dbuser,
#installform #id_dbpass,
#installform #id_prefix {
    direction: ltr;
}

.mdl-right > label {
    // Workaround for repository pop-up because the : are outside the label,
    // can/should be fixed in filemanager renderers.
    display: inline-block;
}

// Checkbox labels. Bootstrap puts the associated checkbox inside the label.
// Moodle puts it beside the label, so we need to make it inline-block
// to keep it on the same horizontal level.
input[type="radio"] + label,
input[type="checkbox"] + label {
    display: inline;
    padding-left: 0.2em;
}
input[type="radio"],
input[type="checkbox"] {
    margin-top: -4px; // Dodgy hack, must be better way.
    margin-right: 7px;
}
.dir-rtl {
    input[type="radio"],
    input[type="checkbox"] {
        margin-left: 7px;
        margin-right: auto;
    }
}
.singleselect {
    display: inline-block;
    form,
    select{
        margin: 0;
    }
}
.form-item .form-label label {
    margin-bottom: 0;
}
.dir-rtl .form-item .form-label label {
     text-align:left;
}
.felement.ffilepicker {
    margin-top: 5px;
}
div#dateselector-calendar-panel {
    z-index: 3100; /* Set higher than the z-index of the filemanager - see MDL-39047. */
}

fieldset.coursesearchbox label {
    display: inline;
}

/**
 * Show the labels above text editors and file managers except on wide screens.
 */
#region-main .mform:not(.unresponsive) .fitem .fitemtitle label {
    font-weight: bold;
}
.makeFormsVertical() {
    #region-main .mform:not(.unresponsive) {
        .fitem {
            .fitemtitle {
                display: block;
                margin-top: 4px;
                margin-bottom: 4px;
                text-align: left;
                width: 100%;
            }
            .felement {
                margin-left: 0;
                width: 100%;
                float: left;
                padding-left: 0;
                padding-right: 0;
            }
            .fstatic:empty {
                display: none;
            }
            .fcheckbox > span,
            .fradio > span,
            .fgroup > span {
                margin-top: 4px;
            }

        }
        .femptylabel {
            .fitemtitle {
                display: inline-block;
                width: auto;
                margin-right: 8px;
            }
            .felement {
                display: inline-block;
                margin-top: 4px;
                padding-top: 5px;
                width: auto;
            }
        }
        .fitem_fcheckbox{
            .fitemtitle,
            .felement {
                display: inline-block;
                width: auto;
            }
            .felement {
                padding: 6px;
            }
        }
    }
    &.dir-rtl #region-main .mform:not(.unresponsive) {
        .femptylabel .fitemtitle {
            margin-right: 0px;
            margin-left: 8px;
        }
        .fitem {
            .fitemtitle {
                text-align: right;
            }
            .felement {
                margin-right: 0;
                float: right;
                padding-right: 0;
                padding-left: 0;
            }
        }
        .fitem_fcheckbox .felement {
            float: right;
        }
    }
}

/**
 * Make forms vertical when the screen is less than 1200px;
 */
@media (max-width: 1199px) {
    body {
        .makeFormsVertical;
    }
}



/**
 * Make forms vertical when the screen is less than 1474px AND both side-pre and side-post contain blocks.
 * This is an extra special media rule.
 * It causes forms to show vertically when the screen size is calculated as:
 * 1199px + (1199px * 23%)
 * Where 23% is the width of span3
 * Full calculation is:
 *   @maxWidthForVerticalForms: 1199px * (unit(((@fluidGridColumnWidth1200 * 3) + (@fluidGridGutterWidth * (3 - 1)))) / 100) + 1199px;
 */
@maxWidthForVerticalForms: 1474px;
@media (max-width: @maxWidthForVerticalForms) {
    .used-region-side-pre.used-region-side-post {
        .makeFormsVertical;
    }
}

/* Section and module editing forms contain special JS components for the
   availability system (if enabled). */
#fitem_id_availabilityconditionsjson {
    *[aria-hidden=true] {
        display: none;
    }
    select,
    input[type=text] {
        position:relative;
        top: 4px;
    }
    label {
        display: inline;
    }
    .availability-group {
        margin-right: 8px;
    }
    .availability-item {
        margin-bottom: 6px;
    }
    .availability-none {
        margin-left: 20px;
        margin-bottom: 4px;
    }
    .availability-plugincontrols {
        padding: 2px 0px 0px 4px;
        background: none repeat scroll 0% 0% @wellBackground;
        border: 1px solid @grayLighter;
        border-radius: 4px;
        display: inline-block;
        margin-right: 8px;
    }
    /* Eye icon in front of an item and delete icon after it. */
    .availability-eye,
    .availability-delete {
        margin-right: 8px;
    }
    /* Hidden eye icon still takes up space. */
    .availability-eye[aria-hidden=true] {
        display: inline;
        visibility: hidden;
    }
    /* Eye icons in front of child lists are aligned specially. */
    .availability-list > .availability-eye img {
        vertical-align: top;
        margin-top: 12px;
    }
    /* Add button lines up with child elements. */
    .availability-button {
        margin-left: 15px;
    }
    /* Nested section is grey. */
    .availability-childlist > .availability-inner {
        display: inline-block;
        background: @wellBackground;
        border: 1px solid @grayLighter;
        border-radius: 4px;
        padding: 6px;
        margin-bottom: 6px;
    }
    /* Second (and more) levels of nested sections are white. */
    .availability-childlist .availability-childlist > .availability-inner {
        background: white;
    }
    /* Connecting text needs to be indented. */
    .availability-connector {
        margin-left: 20px;
        margin-bottom: 6px;
    }
}
.dir-rtl #fitem_id_availabilityconditionsjson {
    .availability-group {
        margin-right: 0;
        margin-left: 8px;
    }
    .availability-none {
        margin-right: 20px;
        margin-left: 0;
    }
    .availability-plugincontrols {
        padding-right: 4px;
        padding-left: 0px;
        margin-right: 0;
        margin-left: 8px;
    }
    .availability-eye,
    .availability-delete {
        margin-left: 8px;
        margin-right: 0;
    }
    .availability-button {
        margin-right: 15px;
        margin-left: 0;
    }
    .availability-connector {
        margin-right: 20px;
        margin-left: 0;
    }
}

/* Default form styling colours all text red. With availability conditions
   this looks excessive as we show 'Invalid' markers in specific places. */
.mform .error .availability-field {
    color: @textColor;
}

/* This dialogue is used to add an availability condition. */
.availability-dialogue {
    .moodle-dialogue .moodle-dialogue-bd {
        padding-left: 0;
        padding-right: 0;
        padding-bottom: 2px;
    }
    ul {
        display: block;
        margin: 0;
    }
    li {
        display: block;
        list-style-type: none;
        padding: 0 0 4px;
        clear: both;
        border-bottom: 1px solid @grayLighter;
        margin-bottom: 4px;
    }
    ul button {
        float: left;
        margin-left: 1em;
        min-width: 140px;
        margin-top: 4px;
    }
    label {
        margin-left: 170px;
        margin-right: 1em;
        margin-bottom: 0;
    }
    .availability-buttons button {
        margin-left: 1em;
        margin-right: 1em;
        margin-top: 4px;
    }
}
.dir-rtl .availability-dialogue {
    ul button {
        float: right;
        margin-right: 1em;
        margin-left: 0;
    }
    label {
        margin-right: 170px;
        margin-left: 1em;
    }
}

/* Revert to the non-fixed width where a textarea has the number of columns
   specified, or an input has it's size specified. */
textarea[cols],
input[size] {
    width: auto;
}

/* Custom styles for autocomplete form element */
.form-autocomplete-selection {
    margin: 0.2em;
    min-height: 21px;
}
.form-autocomplete-multiple [role=listitem] {
    cursor: pointer;
}

.form-autocomplete-suggestions {
    position: absolute;
    background-color: white;
    border: 2px solid @grayLighter;
    border-radius: 3px;
    min-width: 206px;
    max-height: 20em;
    overflow: auto;
    margin: 0px;
    padding: 0px;
    margin-top: -0.2em;
    z-index: 1;
}
.form-autocomplete-suggestions li {
    list-style-type: none;
    padding: 0.2em;
    margin: 0;
    cursor: pointer;
    color: @textColor;
}
.form-autocomplete-suggestions li:hover {
    background-color: lighten(@dropdownLinkBackgroundActive, 15%);
    color: @dropdownLinkColorActive;
}
.form-autocomplete-suggestions li[aria-selected=true] {
    background-color: darken(@navbarBackground, 5%);
    color: @gray;
}

.form-autocomplete-downarrow {
    color: @textColor;
    position: relative;
    top: -0.3em;
    left: -1.5em;
    cursor: pointer;
}
.dir-rtl .form-autocomplete-downarrow {
    right: -1.5em;
    left: inherit;
}

.form-autocomplete-selection:focus {
    outline: none;
}
.form-autocomplete-selection [data-active-selection=true] {
    padding: 0.5em;
    font-size: large;
}
